import { CodeGenerate } from "@/types/admin/codeGenerate";
import { model, Schema, Types } from "mongoose";

const CodeGenerateSchema = new Schema<CodeGenerate>(
    {
        modelName: { type: String, required: true },
        pageName: String,
        collectionName: String,
        desc: String,
        fields: [Types.ObjectId],
        operations: { type: [String], enum: ["create", "getPageList", "getDetail", "parentFind", "update", "delete"] },
        resultTypes: { type: [String], enum: ["admin", "client"] },
        parentFind: { type: { parentModelName: String, localField: String } },
        lookupList: { type: [{ modelName: String, from: String, as: String, localField: String, foreignField: String }] },
        permissionKey: String
    },
    { timestamps: { createdAt: true, updatedAt: true } }
);

export const CodeGenerateModel = model("CodeGenerate", CodeGenerateSchema);
